﻿using UnityEngine;
using System.Collections;
using UnityEditor;

[ExecuteInEditMode]
public class TileAlign
{
	// Constants

	const float				c_tileSize	= 8f;


	[MenuItem("Utility/Align map tiles")]
	public static void AlignMapTiles()
	{
		GameObject[] objects	= Selection.gameObjects;
		foreach (GameObject obj in objects)
		{
			Transform t			= obj.transform;
			Vector3 pos			= t.localPosition;
			//Debug.Log("before : " + pos);
			pos.x				= Mathf.Round(pos.x / c_tileSize) * c_tileSize;
			pos.y				= Mathf.Round(pos.y / c_tileSize) * c_tileSize;
			t.localPosition		= pos;
			//Debug.Log("after : " + pos);
		}
	}
}
